// https://leetcode.cn/problems/lexicographically-smallest-string-after-substring-operation/?envType=daily-question&envId=2024-06-27
class Solution {
public:
    string smallestString(string s) {
        string ret;
        bool t = false;
        int i = 0;
        while(i<s.size() && s[i] == 'a'){
            i++;
            ret.push_back('a');
        }
        if(i == s.size()){
            ret[i-1] ='z';
        }
        for( ; i< s.size();i++){
            if(t == false && s[i] != 'a'){
                ret.push_back(s[i]-1);
            }else{
                t = true;
                ret.push_back(s[i]);
            }
        }
        return ret;
    }
};